/*
 * Copyright (c) TD-Tech Technologies Co., Ltd. 2024-2024. All rights reserved.
 */
export class CommonUtils {
  public static isEmpty(obj): boolean {
    if (typeof obj === 'undefined' || obj == undefined || obj === '' || obj == null || obj === 'null') {
      return true;
    } else {
      return false;
    }
  }

  /**
   * 字符串去除空格后是否为空
   * @param obj
   */
  public static isStrTrimEmpty(obj: string): boolean {
    if (typeof obj === 'undefined' || obj == undefined || obj === '' || obj.trim() === '') {
      return true;
    } else {
      return false;
    }
  }

  public static equals(str1: string, str2: string): boolean {
    return str1 === str2 ? true : false;
  }

  public static equalsIgnoreCase(str1: string, str2: string): boolean {
    if (CommonUtils.isEmpty(str1) || CommonUtils.isEmpty(str2)) {
      return false;
    }
    return str1.toLowerCase() === str2.toLowerCase();
  }

  public static formatFileSize(fileSize: number): string {
    if (fileSize < 1024) {
      return fileSize + 'B';
    } else if (fileSize < (1024 * 1024)) {
      let tempValue = fileSize / 1024;
      return tempValue.toFixed(2) + ' KB';
    } else if (fileSize < (1024 * 1024 * 1024)) {
      let tempValue = fileSize / (1024 * 1024);
      return tempValue.toFixed(2) + ' MB';
    } else {
      let tempValue = fileSize / (1024 * 1024 * 1024);
      return tempValue.toFixed(2) + ' GB';
    }
  }
}